package com.xcx.robot.mirai.util;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: 邢晨旭
 * @Date: 2021/6/9 15:41
 * @Description:
 */
public class KeyUtils {

    private static List<String> getKey(String content) {
        return Arrays.stream(content.split("\\s+")).filter(StringUtils::isNotBlank).collect(Collectors.toList());
    }

    /**
     * 获取一级关键词
     *
     * @param content
     * @return
     */
    public static String getKeyByWord(String content, Integer level) {
        if (StringUtils.isBlank(content)) {
            return "";
        }
        List<String> split = getKey(content);
        if (split.isEmpty() || split.size() < level) {
            return "";
        }
        return split.get(level - 1);
    }
}
